package com.clear.observer.observer;

import com.clear.observer.subject.Subject;

public class ElectronicScreen implements Observer {
    private float temperature;
    private float humidity;
    private float pressure;
    private Subject weatherStation; // 组合主题

    public ElectronicScreen(Subject weatherStation) {
        this.weatherStation = weatherStation;
        weatherStation.registerObserver(this); // 在构造器中注册观察者
    }

    /**
     * 当观察的行为发生了，应该被调用
     */
    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        display();
    }

    public void display() {
        System.out.println("ElectronicScreen: Temperature: " + temperature + "°C, Humidity: " + humidity + "%, Pressure: " + pressure + " hPa");
    }
}
